layui.use(['form', 'layer', 'jquery', 'table', 'element','laydate','transfer'], function() {
	var form = layui.form,
		layer = layui.layer,
		$ = layui.$,
		table = layui.table,
		element = layui.element,laydate=layui.laydate,transfer=layui.transfer;
	//基本信息管理
	form.on('submit(*)', function(data) {
		layer.msg('信息保存成功!', {
			icon: 1
		});
	});
	//删除
	$('[lay-filter=delete]').click(function() {
		
		
		layer.msg('确定删除此门类吗!', {
			time: 0,
			btn: ['确定', '取消'],
			title: '提示',
			skin: 'demo-class',
			yes: function(index) {

			}
		})
	})
	// 门类字段管理

	var table2 = table.render({
		elem: '#demo1',
		size: 'sm',
		toolbar: '#btn-mb',
		id:'table2cz',
		title: '字段信息预览',
		cellMinWidth: 80,
		height:500,
		limit: Number.MAX_VALUE,
		cols: [
			[{
					type: 'radio'
				},
				{
					type: 'numbers',
					title: '序号'
				}, {
					field: 'Chinaname',
					title: '中文名称',
					unresize: true,
					sort: true,
					width: 120,
					align: 'center', edit: 'text'
				}, {
					field: 'Engname',
					title: '英文名称',
					unresize: true,
					sort: true,
					width: 120,
					align: 'center', edit: 'text'
				}, {
					field: 'isDataTypea',
					title: '字段类型',
					templet: '#checkbox1-1',
					align: 'center'
				},
				{
					field: 'isColumnLength',
					title: '字段长度',
					sort: true,
					align: 'center', edit: 'text'
				},{
					field: 'dxk2',
					title: '是否主键',
					templet: '#checkbox1-2',
					align: 'center'
				},
				{
					field: 'dxk3',
					title: '是否为空',
					templet: '#checkbox1-3',
					align: 'center'
				},{
					field: 'isDataType',
					title: '备注',
					align: 'center' ,edit: 'text'
				}
			]
		]
		,data:[{
	"Chinaname":"机构（问题）",
    "Engname":"archive_ctg_no",
	"isDataType":"字符",
	"isColumnLength":"50",
	"isInputClass":"下拉框",
	"isDefaultValueType":"机构（问题）",
	"maincenter":"245"
  },{
	"Chinaname":"归档日期",
    "Engname":"pigeonhole_date",
	"isDataType":"字符",
	"isColumnLength":"20",
	"isInputClass":"日期框",
	"isDefaultValueType":"",
	"maincenter":"245"
  },{
	"Chinaname":"盒号",
    "Engname":"case_no",
	"isDataType":"字符",
	"isColumnLength":"10",
	"isInputClass":"数字框",
	"isDefaultValueType":"",
	"maincenter":"245"
  },{
	"Chinaname":"存放目录",
    "Engname":"folder_location",
	"isDataType":"字符",
	"isColumnLength":"50",
	"isInputClass":"文本框",
	"isDefaultValueType":"",
	"maincenter":"245"
  },{
	"Chinaname":"全宗号",
    "Engname":"fonds_no",
	"isDataType":"字符",
	"isColumnLength":"100",
	"isInputClass":"弹出框",
	"isDefaultValueType":"全宗号",
	"maincenter":"245"
  },{
	"Chinaname":"机构（问题）",
    "Engname":"archive_ctg_no",
	"isDataType":"字符",
	"isColumnLength":"50",
	"isInputClass":"下拉框",
	"isDefaultValueType":"机构（问题）",
	"maincenter":"245"
  },{
	"Chinaname":"页数",
    "Engname":"page_no",
	"isDataType":"字符",
	"isColumnLength":"10",
	"isInputClass":"数字框",
	"isDefaultValueType":"",
	"maincenter":"245"
  },{
	"Chinaname":"密级",
    "Engname":"security_class",
	"isDataType":"字符",
	"isColumnLength":"10",
	"isInputClass":"下拉框",
	"isDefaultValueType":"",
	"maincenter":"245"
  },{
	"Chinaname":"立卷人",
    "Engname":"collator",
	"isDataType":"字符",
	"isColumnLength":"50",
	"isInputClass":"文本框",
	"isDefaultValueType":" ",
	"maincenter":"245"
  }]
		
	});
	table.on('edit(test2)', function(obj){
	    var value = obj.value //得到修改后的值
	    ,data = obj.data //得到所在行所有键值
	    ,field = obj.field; //得到字段
	    layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
	  });
	var objfz
	var objfa
	table.on('row(test2)', function(obj) {
		obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
		obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click");
		objftr=obj;
		objfz = obj.tr;
	});
	table.on('toolbar(test2)', function(obj) {
		var checkStatus = table.checkStatus(obj.config.id);
		data_tr=objfz
		switch (obj.event) {
			case 'cjzd':
				 var oldData = table.cache['table2cz'];
				  var data1={"Chinaname":"","Engname":"","isDataType":"","isColumnLength":"","isInputClass":"","isDefaultValueType":"","maincenter":""};
				  oldData.push(data1);
				  table.reload('table2cz',{
					  data :oldData
				  });
				  $("#createform table tbody tr:last-child td[data-fieid=Chinaname]").focus();
				break;
			case 'deletezd':
				if(objfz!=null){
					layer.msg('确定删除此字段吗!', {
						time: 0,
						btn: ['确定', '取消'],
						title: '提示',
						skin: 'demo-class',
						yes: function(index) {
							objftr.del();
							layer.msg('删除成功',{icon:1})
						}
					})
				}else{
					layer.msg('请选中一行',{icon:3})
				}
				break;
			case 'sy':
				if(data_tr==null){
					layer.msg('请选中一行',{icon:3})
					return;
				}
				if($(data_tr).prev().html()==null){
					layer.msg('已经到顶了',{icon:3})
					return
				}else{
					$(data_tr).insertBefore($(data_tr).prev());
				}
			break;
			case 'xy':
				if(data_tr==null){
					layer.msg('请选中一行',{icon:3})
					return;
				}
				if($(data_tr).next().html()==null){
					layer.msg('已经到底了',{icon:3})
					return
				}else{
					$(data_tr).insertAfter($(data_tr).next());
				}
			break;
			case 'bc':
				layer.msg('保存成功',{icon:1})
					
			break
		};
	});
		
	
	laydate.render({
		elem:'#data1',
		type:'year'
	})
	laydate.render({
		elem:'#data2'
	})
	laydate.render({
		elem:'#data3'
	})
	// 浏览界面设计
	var table3=table.render({
		elem:'#demo2',
		url: '../../layuiadmin/json/Categoryb.json',
		toolbar:'#btn-lljm',
		size: 'sm',
		height:300,
		cols:[[
			{type: 'radio'},
			{type: 'numbers',title: '序号'},
			{field:'fieldCnName',title:'字段名称',	align: 'center', edit: 'text'},
			{field:'isDisplayWidth',title:'显示长度',	align: 'center', edit: 'text'},
			{field:'isDisplayAlign',title:'显示格式',	align: 'center',templet: '#select1'},
			{field:'isnullzd',title:'是否检索',templet: '#checkboxis1',	align: 'center'},
			{field:'hidezd',title:'是否隐藏',templet: '#checkboxis2',align: 'center'},
			{field:'paixuzd',title:'是否排序',templet: '#checkboxis3',align: 'center'},
			
		]]
	})
	table.on('edit(test3)', function(obj){
	    var value = obj.value //得到修改后的值
	    ,data = obj.data //得到所在行所有键值
	    ,field = obj.field; //得到字段
	    layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
	  });
	table.on('row(test3)', function(obj) {
		obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
		obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click");
		objfz = obj;
		objfa=obj.tr;
	});
	
	table.on('toolbar(test3)',function(obj){
		 var checkStatus = table.checkStatus(obj.config.id);
		data_tr=objfa
		switch(obj.event){
			case 'sy':
				if(data_tr==null){
					layer.msg('请选中一行',{icon:3})
					return;
				}
				if($(data_tr).prev().html()==null){
					layer.msg('已经到顶了',{icon:3})
					return
				}else{
					$(data_tr).insertBefore($(data_tr).prev());
				}
			break;
			case 'xy':
				if(data_tr==null){
					layer.msg('请选中一行',{icon:3})
					return;
				}
				if($(data_tr).next().html()==null){
					layer.msg('已经到底了',{icon:3})
					return
				}else{
					$(data_tr).insertAfter($(data_tr).next());
				}
			break;
			case 'bc':
				layer.msg('保存成功',{icon:1})
					
			break
		}
	})
	//表4
	var table3=table.render({
		elem:'#demo3',
		url: '../../layuiadmin/json/Categoruya-text4.json',
		size: 'sm',
		height:300,
		cols:[[
			{type: 'checkbox'},
			{type: 'numbers',title: '序号'},
			{field:'department',title:'部门名称',	align: 'center'},
			{field:'archive_no',title:'档号',	align: 'center'},
			{field:'filing_year',title:'归档年度',	align: 'center'},
			{field:'archive_ctg_no',title:'机构（问题）',	align: 'center'},
			{field:'retention',title:'保管期限',	align: 'center'},
			{field:'piece_no',title:'件号',	align: 'center'},
			{field:'doc_no',title:'文号',	align: 'center'},
			{field:'maintitle',title:'题名',	align: 'center'},
			{field:'created_date',title:'文件形成时间',	align: 'center'},
			{field:'page_no',title:'页数',	align: 'center'},
			{field:'responsibleby',title:'责任者',	align: 'center'},
			{field:'pigeonhole_date',title:'归档日期',	align: 'center'}
		]]
		
	})
	table.on('row(test4)', function(obj) {
			obj.tr.toggleClass('layui-table-click')
			obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click");
			obj.tr.find('[lay-skin=primary]').toggleClass("layui-form-checked");
			objfz = obj;
			objfa=obj.tr;
		});
	
	var buttonali=$(".layui-tab-item3-left-btn ul li:nth-child(1)")
	
	$(".layui-tab-item3-left-btn ul li button").click(function(){
		$(this).parent().siblings().find('button').removeClass("layui-btn-normal");
		$(this).toggleClass("layui-btn-normal")
		buttonali=$(this).parent()
	})
	$(".layui-btn-sw").click(function(){
		$(".layui-tab-item3-left-btn ul li").eq(0).before(buttonali)
	})
	$(".layui-btn-qy").click(function(){
		
		if(buttonali.prev().html()==null){
			layer.msg('已经到顶了',{icon:3})
			return
		}else{
			buttonali.insertBefore(buttonali.prev());
		}
	})
	$(".layui-btn-hy").click(function(){
		if(buttonali.next().html()==null){
			layer.msg('已经到底了',{icon:3})
			return
		}else{
			buttonali.insertAfter(buttonali.next());
		}
		
	})
	$(".layui-btn-mw").click(function(){
		$(".layui-tab-item3-left-btn ul li").last().after(buttonali)
	})
	
	
	
})
